"use strict";
/* Controllers */
app.controller("ruledocListController", ['$scope', '$location', '$rootScope', '$routeParams', 'ruledocListService', function ($scope, $location, $rootScope, $routeParams, ruledocListService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.result = {};
    vm.p.clusterName = $routeParams.cluster;
    vm.p.queue= $routeParams.queue;


    var errorFn = function (result) {
        alert(result);
    };


    var ruleDefines = [
        {id: 1, ruleType: '开发规范', ruleName: '表命名规范', docHref: 'https://docs.qq.com/sheet/DRWhKUVNUbmhGSlRY?tab=c9d64t', ownerId: 'lixiyong01', updateTime:'2021-12-17 11:01:01'},
        {id: 11, ruleType: '开发规范', ruleName: '数仓分层规范', docHref: 'https://docs.qq.com/sheet/DRWhKUVNUbmhGSlRY?tab=BB08J2', ownerId: 'lixiyong01', updateTime:'2021-12-17 11:01:01'},
        {id: 2, ruleType: '开发规范', ruleName: '业务定义码表', docHref: 'https://docs.qq.com/sheet/DRWhKUVNUbmhGSlRY?tab=q91ip9', ownerId: 'lixiyong01', updateTime:'2021-12-17 11:01:01'},
        {id: 3, ruleType: '开发规范', ruleName: '表归属管理规范', docHref: 'https://docs.qq.com/sheet/DSFFCYVNiUVR6b3JC?tab=v2vv0v', ownerId: 'lixiyong01', updateTime:'2021-12-17 11:01:01'},
        {id: 4, ruleType: '开发规范', ruleName: '表生命周期管理规范', docHref: 'https://docs.qq.com/sheet/DRWhKUVNUbmhGSlRY?tab=c9d64t', ownerId: 'lixiyong01', updateTime:'2021-12-17 11:01:01'},
        {id: 5, ruleType: '开发规范', ruleName: 'P0级任务管理规范', docHref: 'http://iwiki.58corp.com/shorturl/3qbpIIsMBb', ownerId: 'lixiyong01', updateTime:'2021-12-17 11:01:01'},
        {id: 6, ruleType: '开发规范', ruleName: '常用词根表', docHref: 'https://docs.qq.com/sheet/DRWhKUVNUbmhGSlRY?tab=mqhwia', ownerId: 'lixiyong01', updateTime:'2021-12-17 11:01:01'},
        {id: 7, ruleType: '开发规范', ruleName: 'UDF函数管理规范', docHref: 'https://docs.qq.com/sheet/DSGJxVWxTVHZQcVRa?tab=d7tq3w', ownerId: 'lixiyong01', updateTime:'2021-12-17 11:01:01'},
        {id: 8, ruleType: '安全规范', ruleName: '数据安全管理规范', docHref: 'https://docs.qq.com/sheet/DSGJxVWxTVHZQcVRa?tab=d7tq3w', ownerId: 'lixiyong01', updateTime:'2021-12-17 11:01:01'}
    ];

    $scope.listRuledoc = function () {
        var vm = $scope.vm;
        $('#list_table').bootstrapTable('load', ruleDefines);
        //vm.result.ms = "...";
        //var params = {clusterName: vm.p.clusterName, queue: vm.p.queue};
        //var procFn = function (response) {
        //    vm.result.ms = response.ms;
        //    var data = response.data;
        //    if (data == null) return;
        //    vm.result.data = data;
        //    $('#list_table').bootstrapTable('load', data);
        //};
        //ruledocListService.listRuledoc(params, procFn, errorFn);
    };

    $scope.initializeController = function () {
        vm.result.ms = '';
        var $resultTable = $('#list_table');
        $resultTable.bootstrapTable({
             pageList: [30, 50, 100, 300, 500, 1000], pageSize: 30
        });
        //$resultTable.bootstrapTable('hideColumn', 'action');
        $scope.listRuledoc();
    };

    $scope.initializeController();

}]);


/* Services */
app.service('ruledocListService', ['ajaxService', function (ajaxService) {

    this.listRuledoc = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/ruledoc/listRuledoc.do", successFunction, errorFunction);
    };

    this.deleteRuledoc = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/ruledoc/deleteRuledoc.do", successFunction, errorFunction);
    };
}]);

function queueTypeFmt(value, row, index) {
    if (value == null) {
        return "-";
    }
    switch (value) {
        case 0:
            return "动态";
        case 1:
            return "固定";
        default:
            return "-";
    }
}

function docHrefFmt(value, row, index) {
    if (value == null) {
        return "-";
    }
    return [
        '<a href="', value,'" target="_blank">', "<u>",value,"</u>" , '</a>'
    ].join('');
}


